<template>
	<view>
		<view class="container">
			<uni-list>
				<uni-list-item title="账号管理" @clickFn="changePassword" v-if="IsLogin" />
				<!-- #ifdef APP-PLUS -->
				<uni-list-item title="消息通知" :rightText="this.tuisong?'通知已开启':'已关闭去开启'" @clickFn="Tuisong" />
				<uni-list-item title="给我们评分" @clickFn="openMarket('com.tencent.android.qqdownloader')" />
				<uni-list-item title="推荐app" @clickFn="shareOn" />
				<!-- #endif -->
				<uni-list-item title="隐私政策" @clickFn="toYinsizhengce" />
				<uni-list-item title="服务条款" @clickFn="toFuwutiaokuan" />
				<uni-list-item title="关于我们" @clickFn="AboutUs"><template v-slot:right=""></template></uni-list-item>
				<uni-list-item title="注销账户" @clickFn="zhuxiaoPopup('center')" v-if="IsLogin" />
				<uni-list-item title="退出登录" v-if="IsLogin" @clickFn="togglePopup('center', 'tip')" />
				<uni-list-item title="退出登录" :disabled="true" v-else />
			</uni-list>
			<!-- <uni-popup ref="sharepopup" type="bottom">
				<share-btn :sharedataTemp="sharedata"></share-btn>
			</uni-popup> -->
		</view>
		<!-- <view class="return-btn"> -->
		<!-- <button type="primary" :class="IsLogin?'return-btn1 return-btn2':'return-btn1'"
				@click="togglePopup('center', 'tip')" v-if="IsLogin">退出登录</button>
			<button type="primary" class="return-btn1" disabled="true" v-else>退出登录</button> -->
		<!-- <button type="primary" class='return-btn1 return-btn2' @click="zhuxiao()" v-if="IsLogin" style='margin-top: 30rpx;background-color:#9a9a9a;'>注销账号</button> -->
		<!-- <button type="primary" class='return-btn1 return-btn2' @click="zhuxiaoPopup('center')" v-if="IsLogin"
				style='margin-top: 30rpx;background-color:#9a9a9a;'>注销账号</button>
		</view> -->
		<!-- 退出登录 -->
		<uni-popup ref="showtip" :type="type" :mask-click="false">
			<view class="uni-tip">
				<text class="uni-tip-title">提示</text>
				<text class="uni-tip-content">您确定要退出吗？</text>
				<view class="uni-tip-group-button">
					<text class="uni-tip-button" @click="cancel('tip')">取消</text>
					<text class="uni-tip-button" @click="doLogoutUser('tip')">确定</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="zhuxiao" :mask-click="false">
			<view class="uni-tip">
				<text class="uni-tip-title">注销账号</text>
				<text class="uni-tip-content">您注销后您的注册资料将会被销毁，您将无法继续使用采招网的所有产品以及服务，您确认注销帐号吗？</text>
				<view class="uni-tip-group-button">
					<text class="uni-tip-button" @click="closeZhuxiao()">取消</text>
					<text class="uni-tip-button" @click="toZhuxiao()">确定</text>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	// #ifdef APP-PLUS
	import appShare from '../../../common/static/share.js';
	// #endif
	export default {
		components: {
			uniPopup
		},
		data() {
			return {
				type: '',
				tuisong: false,
				CacheSize: '0kb',
				IsLogin: false,
				sharedata: {
					type: 0,
					strShareUrl: "https://m.bidcenter.com.cn/help/downloadapp.shtml",
					strShareTitle: "采招网-招标网|招标公告|工程招标采购信息",
					strShareSummary: "中国采招网是致力于为企业提供招标采购等服务的招标网",
					strShareImageUrl: "https://img.bidcenter.com.cn/app/images/logo.png"
				},
				yszcUrl: '',
				fwtkUrl: ''
			}
		},
		onLoad() {
			this.checkLogin();
			this.IsLogin = this.currUser.islogin;
			// #ifdef APP-PLUS
			this.isKaiqiTongzhi();
			// #endif 
			// #ifdef APP-PLUS
			// var currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效，非v3编译模式使用this.$mp.page.$getAppWebview()
			// setTimeout(function() {
			// 	console.log(2,currentWebview)
			// 	let wv = currentWebview.children()[0];
			// 	wv.setStyle({
			// 		videoFullscreen: 'landscape'
			// 	});
			// }, 200); 
			//如果是页面初始化调用时，需要延时一下
			// #endif
		},
		onShow() {
			this.checkLogin();
			this.IsLogin = this.currUser.islogin;
			// #ifdef APP-PLUS
			this.isKaiqiTongzhi();
			// #endif 
			this.yszcUrl = '',
				this.fwtkUrl = ''
		},

		methods: {

			// 跳转到隐私政策及服务条款
			toYinsizhengce() {
				var url = 'https://www.bidcenter.com.cn/help/yszc.shtml?t=202211021809'
				uni.navigateTo({
					url: '/pages/user/yinsitiaokuan/yinsitiaokuan?url=' + url
				})
			},
			toFuwutiaokuan() {
				var url = 'https://www.bidcenter.com.cn/help/fwtk.shtml'
				uni.navigateTo({
					url: '/pages/user/yinsitiaokuan/yinsitiaokuan?url=' + url
				})
			},

			//注销账号
			zhuxiaoPopup() {
				this.$refs.zhuxiao.open()
			},
			toZhuxiao() {
				this.$refs.zhuxiao.close()
				uni.navigateTo({
					url: '../logout/logout'
				})
			},
			closeZhuxiao() {
				this.$refs.zhuxiao.close()
			},
			setpassword() {
				uni.navigateTo({
					url: '../SetPassword/SetPassword'
				})
			},
			AboutUs() {
				uni.navigateTo({
					url: '../AboutUs/AboutUs'
				})
			},
			doLogoutUser() {
				// debugger
				if (this.IsLogin) {
					let data = this.initNewData();
					data.from = 4038;
					data.location = 8092;
					// debugger
					uni.request({
						url: this.baseConfig.serverURL + '/User/setting/DelCacheHandler.ashx', //检查更新的服务器地址
						data: data,
						method: "POST",
						header: {
							"content-type": "application/x-www-form-urlencoded" //"application/json"
						},
						success: (res) => {}
					})
				}
				this.doLogout();
				// this.currUser = this.doLogout();
				uni.switchTab({
					url: '../user'
				})
			},
			togglePopup(type, open) {
				this.type = type
				// this.$nextTick(() => {
				// 	this.$refs['show' + open].open()
				// })
				this.$refs['show' + open].open()
			},
			cancel(type) {
				this.$refs['show' + type].close()
			},
			onShare() {
				let shareData = {
					shareUrl: "https://m.bidcenter.com.cn/help/downloadapp.shtml",
					shareTitle: "采招网--招标网|招标公告|工程招标采购信息",
					shareContent: "中国采招网是招标网中致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等服务的招标网;采招网是中国招标网站采购领域的最佳资讯和交易招标网站，为各级政府采购、招标代理机构、招标企业、供应商提供强大的专业招标采购信息查询和相关服务,中国第一招标网",
					shareImg: 'https://img.bidcenter.com.cn/app/images/logo.png'
				};
				// 调用
				//#ifdef APP
				appShare(shareData, res => {
					console.log("分享成功回调", res);
				});
				//#endif
			},
			// shareContent() {
			// 	// 分享内容配置
			// 	const shareData = {
			// 		title: '采招网--招标网|招标公告|工程招标采购信息', // 分享标题
			// 		summary: '中国采招网是招标网中致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等服务的招标网;采招网是中国招标网站采购领域的最佳资讯和交易招标网站，为各级政府采购、招标代理机构、招标企业、供应商提供强大的专业招标采购信息查询和相关服务,中国第一招标网', // 分享摘要
			// 		href: 'https://m.bidcenter.com.cn/help/downloadapp.shtml', // 分享链接，非必填
			// 		imageUrl: 'https://img.bidcenter.com.cn/app/images/logo.png', // 图片链接，非必填
			// 		type: 'text', // 分享类型，可选值有：text（文本）、image（图片）、miniprogram（小程序）
			// 		provider: 'weixin', // 分享到的平台，可选值有：weixin, qq, sinaweibo, alipay, qzone, ...
			// 		success: function(res) {
			// 			console.log('分享成功！', res);
			// 		},
			// 		fail: function(err) {
			// 			console.log('分享失败！', err);
			// 		}
			// 	};
			// 	// 调用分享功能
			// 	uni.share(shareData);
			// },
			shareOn() {
				const systemInfo = uni.getSystemInfoSync()
				if (systemInfo.platform == 'ios') {
					this.onShare();
				} else {
					// #ifdef  APP-PLUS
					let shareInfo = {
						href: "https://m.bidcenter.com.cn/help/downloadapp.shtml",
						title: "采招网-招标网|招标公告|工程招标采购信息",
						desc: "中国采招网是招标网中致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等服务的招标网;采招网是中国招标网站采购领域的最佳资讯和交易招标网站，为各级政府采购、招标代理机构、招标企业、供应商提供强大的专业招标采购信息查询和相关服务,中国第一招标网",
						imgUrl: "https://img.bidcenter.com.cn/app/images/logo.png"
					};
					plus.share.sendWithSystem({
						type: "text",
						title: shareInfo.title || "",
						thumbs: [shareInfo.imgUrl || ""],
						href: shareInfo.href || "",
						content: shareInfo.desc || "",
					})
					// #endif
					// #ifdef APP-HARMONY
					// console.log(11, uni.getSystemInfoSync().platform)
					try {
						// 引入鸿蒙原生插件
						const harmonyApi = uni.requireNativePlugin('HarmonyOSApi');

						// 调用鸿蒙分享能力
						harmonyApi.shareContent({
							type: 'text', // 支持 text, image, web, file 等
							data: {
								title: "采招网-招标网|招标公告|工程招标采购信息",
								description: "中国采招网是招标网中致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等服务的招标网;采招网是中国招标网站采购领域的最佳资讯和交易招标网站，为各级政府采购、招标代理机构、招标企业、供应商提供强大的专业招标采购信息查询和相关服务,中国第一招标网",
								url: "https://m.bidcenter.com.cn/help/downloadapp.shtml",
								imagePath: "https://img.bidcenter.com.cn/app/images/logo.png"
							},
							success: function(res) {
								console.log('鸿蒙分享成功', res);
							},
							fail: function(err) {
								console.error('鸿蒙分享失败', err);
							}
						});
					} catch (e) {
						console.error('调用鸿蒙分享API失败', e);
						// 降级处理，使用普通分享
						uni.share({
							provider: 'system',
							type: 0,
							title: '采招网--招标网|招标公告|工程招标采购信息', // 分享标题
							summary: '中国采招网是招标网中致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等服务的招标网;采招网是中国招标网站采购领域的最佳资讯和交易招标网站，为各级政府采购、招标代理机构、招标企业、供应商提供强大的专业招标采购信息查询和相关服务,中国第一招标网', // 分享摘要
							href: 'https://m.bidcenter.com.cn/help/downloadapp.shtml', // 分享链接，非必填
						});
					}
					// #endif

				}

				//this.$refs.sharepopup.open();
			},
			isKaiqiTongzhi() {
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == 'ios') {
					var UIApplication = plus.ios.import("UIApplication");
					var app = UIApplication.sharedApplication();
					var enabledTypes = 0;
					if (app.currentUserNotificationSettings) {
						var settings = app.currentUserNotificationSettings();
						enabledTypes = settings.plusGetAttribute("types");
						console.log("enabledTypes1:" + enabledTypes);
						if (enabledTypes == 0) {
							this.tuisong = false;
						} else {
							this.tuisong = true;
						}
					} else {
						enabledTypes = app.enabledRemoteNotificationTypes();
						if (enabledTypes == 0) {
							this.tuisong = false;
						} else {
							this.tuisong = true;
						}
						console.log("enabledTypes2:" + enabledTypes);
					}
					plus.ios.deleteObject(app);

				} else if (uni.getSystemInfoSync().platform == 'android') {
					//安卓
					let main = plus.android.runtimeMainActivity();
					let pkName = main.getPackageName();
					let NotificationManagerCompat = plus.android.importClass(
						"android.support.v4.app.NotificationManagerCompat");

					// android.support.v4升级为androidx
					if (NotificationManagerCompat == null) {
						NotificationManagerCompat = plus.android.importClass(
							"androidx.core.app.NotificationManagerCompat");
					}

					let packageNames = NotificationManagerCompat.from(main);
					if (!packageNames.areNotificationsEnabled()) { //手机没有开启通知的权限
						this.tuisong = false;
					} else {
						this.tuisong = true;
					}
				}
				// #endif 
			},
			Tuisong() {
				/* 获取当前手机是否有通知权限 */
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == 'ios') {
					var app = plus.ios.invoke('UIApplication', 'sharedApplication');
					var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
					plus.ios.invoke(app, 'openURL:options:completionHandler:', setting);
					plus.ios.deleteObject(setting);
					plus.ios.deleteObject(app);
				} else if (uni.getSystemInfoSync().platform == 'android') {
					//安卓
					let main = plus.android.runtimeMainActivity();
					let pkName = main.getPackageName();
					let NotificationManagerCompat = plus.android.importClass(
						"android.support.v4.app.NotificationManagerCompat");

					let uid = main.getApplicationInfo().plusGetAttribute("uid");
					let Intent = plus.android.importClass('android.content.Intent');
					let Build = plus.android.importClass("android.os.Build");
					//android 8.0引导  
					if (Build.VERSION.SDK_INT >= 26) {
						let intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
						intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
						// 跳转到该应用的系统通知设置页
						main.startActivity(intent);
					} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0  
						let intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
						intent.putExtra("app_package", pkName);
						intent.putExtra("app_uid", uid);
						// 跳转到该应用的系统通知设置页
						main.startActivity(intent);
					} else { //(<21)其他--跳转到该应用管理的详情页
						let Settings = plus.android.importClass("android.provider.Settings");
						let Uri = plus.android.importClass("android.net.Uri");
						let intent = new Intent();
						intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
						let uri = Uri.fromParts("package", main.getPackageName(), null);
						intent.setData(uri);
						// 跳转到该应用的系统通知设置页
						main.startActivity(intent);
					}
				}
				// #endif 
				/* 获取当前手机是否有通知权限 */
			},
			openMarket(marketPackageName) { //打开应用商店评分
				// #ifdef APP-PLUS
				var appurl;
				console.log(uni.getSystemInfoSync().platform)
				if (uni.getSystemInfoSync().platform.toLowerCase() == "android") {
					//appurl = "market://details?id=com.tencent.mm"; //由于hello uni-app没有上Android应用商店，所以此处打开了另一个示例应用  
					var Uri = plus.android.importClass("android.net.Uri");
					var uri = Uri.parse("market://details?id=" + 'com.bidcenter.mm');
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
				} else if (uni.getSystemInfoSync().platform == "ios") {
					appurl =
						"itms-apps://itunes.apple.com/cn/app/com.bidcenter.iosapp/id890317566?mt=8&action=write-review"
					plus.runtime.openURL(appurl, function(res) {
						console.log(res);
					});
				}
				// #endif 

				// #ifdef APP-HARMONY

				// console.log(plus.runtime)
				// 华为应用商店的URI
				// https://appgallery.huawei.com/link/invite-test-wap?taskId=2d70c5f93334737fbcf808f2eb65c010 测试app链接
				var url =
					"intent://com.huawei.appmarket.ECS#/ecs?package=com.bidcenter.huawei&appId=__UNI__2F5F9D0&tabId=0&enterFrom=1";
				// 上线后测试，目前支持 plus.runtime.openURL
				plus.runtime.openURL(url, function(event) {
					console.log("打开链接成功");
				}, function(error) {
					console.log("打开链接失败: " + error.message);
				});

				// #endif 
			},
			// getCache() {
			// 	// 使用plus.cache.calculate 获取应用的缓存大小，
			// 	var cacheSize = '0';
			// 	plus.cache.calculate(function(size) { //size是多少个字节单位是b
			// 		//你可以做下面相应的处理
			// 		if (size < 1024) {
			// 			cacheSize = size + 'B';
			// 		} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
			// 			cacheSize = Math.floor(size / 1024 * 100) / 100 + 'KB';
			// 		} else if (size / 1024 / 1024 >= 1) {
			// 			cacheSize = Math.floor(size / 1024 / 1024 * 100) / 100 + 'M';
			// 		}
			// 	});
			// 	return cacheSize;
			// },
			changePassword() {
				if (this.IsLogin) {
					let data = this.initNewData();
					data.from = 4038;
					data.location = 1;
					uni.request({
						url: this.baseConfig.serverURL +
							'/user/login/UserLoginStateCheckHandler.ashx', //检查更新的服务器地址
						data: data,
						method: "POST",
						header: {
							"content-type": "application/x-www-form-urlencoded" //"application/json"
						},
						success: (res) => {
							if (res.statusCode == 200) {
								if (res.data.ret) {
									if (res.data.other2.ispc) {
										uni.showModal({
											content: "您的帐号是PC端会员，为了您的帐号安全，请您在采招网用户中心帐号管理中进行修改。",
											showCancel: false
										})
									} else {
										this.setpassword();
									}
								}
							}
						},
						fail: (res) => {
							uni.showToast({
								title: '清除缓存失败！',
								icon: "none"
							});
						}
					})
				}
			},
			zhuxiao() {
				uni.showModal({
					content: "如需要注销帐号，请拨打4008109688",
					showCancel: false
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '../../../common/common.css';

	.return-btn {
		width: 90%;
		margin: 100rpx auto 0;
	}

	.return-btn1::after {
		border: 0;
	}

	.return-btn1 {
		border-radius: 50rpx;
		background-color: #ccc;
	}

	.return-btn1[disabled][type=primary] {
		background-color: #ccc;
	}

	.return-btn2 {
		background-color: #2c6bc5;
	}

	/* 提示窗口 */
	.uni-tip {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		padding: 15px;
		width: 300px;
		background-color: #fff;
		border-radius: 10px;
		margin: 0 auto;
	}

	.uni-tip-title {
		margin-bottom: 10px;
		text-align: center;
		font-weight: bold;
		font-size: 16px;
		color: #333;
	}

	.uni-tip-content {
		/* padding: 15px;
	*/
		font-size: 14px;
		color: #666;
	}

	.uni-tip-group-button {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		margin-top: 20px;
	}

	.uni-tip-button {
		flex: 1;
		text-align: center;
		font-size: 14px;
		color: #3b4144;
	}

	/* 底部分享 */
	.shareTo {
		position: relative;

		&:hover>div.shareToBox {
			display: block;
		}

		>div.shareToBox {
			position: absolute !important;
			top: calc(100%);
			left: 50% !important;
			transform: translateX(-50%) !important;
			padding-top: 20px;
			display: none;
			z-index: 3;

			>div {
				min-width: 142px !important;
				height: initial !important;
				box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.09);
				border: 0 !important;
				padding: 16px 26px;
				cursor: initial;
				background-color: #fff !important;
				position: relative;

				>.arrow {
					position: absolute;
					top: -12px;
					left: 50%;
					content: "";
					transform: translateX(-50%);
					width: 0;
					height: 0;
					border-right: 12px solid transparent;
					border-bottom: 12px solid #eee;
					border-left: 12px solid transparent;

					&::before {
						position: absolute;
						top: 1px;
						left: 50%;
						content: "";
						transform: translateX(-50%);
						width: 0;
						height: 0;
						border-right: 12px solid transparent;
						border-bottom: 11px solid #fff;
						border-left: 12px solid transparent;
					}
				}

				>.shareList {
					display: flex;
					padding: 10px 0px;
					display: flex;
					align-items: center;
					cursor: pointer;

					&:nth-child(2) {
						i {
							color: #facc00;
						}
					}

					&:nth-child(3) {
						i {
							color: #3389ff;
						}
					}

					&:nth-child(4) {
						i {
							color: #f67f37;
						}
					}

					&:nth-child(5) {
						i {
							color: #80d642;
						}
					}

					>i {
						font-size: 28px;
						margin-right: 10px;
					}

					>span {
						font-size: 14px;
						color: #999999;
						white-space: nowrap;
					}
				}

				>.shareCanvas {
					width: 100%;

					img {
						width: 100%;
					}
				}
			}
		}
	}
</style>